<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>{$meta_title}</h2>
    </div>
    <form action="{:U('saveAnswer')}" method="post" class="form-horizontal">
        <div class="form-item">
            <label class="item-label">选择课程<span class="check-tips"></span></label>
            <div class="controls">
                <select name="course_id" id="course_id" style="width: 400px;">
                    <volist name="courselist" id="vo">
                    <option value="{$vo.id}" <php>if($vo['id']==$data['course_id'])echo 'selected="selected"';</php>>{$vo.title}</option>
                    </volist>
                </select>
            </div>
        </div>

        <div class="form-item" id="_html_tip" style="margin: 20px 0;">
            <a class="btn" onclick="answer(1)">生成题目</a>
        </div>



        <div class="form-item">
            <button class="btn submit-btn ajax-post" style="display: none;" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
        <input type="hidden"  name="id" value="{$data.id}" >
        <input type="hidden"  name="learn_id" id="learn_id" value="" >
    </form>
</block>

<block name="script">
    <script type="text/javascript">

        //生产评估题目
        function answer() {
            var course_id = $("#course_id").val();

            $.ajax({
                type: 'POST',
                url: "{:U('ajaxAnswer')}",
                data: "course_id="+course_id,
                success: function (res) {
                    if(res.status==1){
                        var learn_id = res.learn_id;
                        var list = res.question;
                        var html = '';
                        var i = 1;
                        for (j in list)
                        {
                            html += "<div class=\"form-item\">\n" +
                                "            <label class=\"item-label\">"+i+"、"+list[j]['question']+"<span class=\"check-tips\"></span></label>\n" +
                                "            <div class=\"controls\">\n" +
                                "                <label class=\"textarea input-large\">\n" +
                                "                    <textarea name=\"answer[]\"></textarea>\n" +
                                "                    <input type=\"hidden\"  name=\"qid[]\" value=\""+list[j]['id']+"\" >\n" +
                                "                    <input type=\"hidden\"  name=\"qtitle[]\" value=\""+list[j]['question']+"\" >\n" +
                                "                </label>\n" +
                                "            </div>\n" +
                                "        </div>";
                            i++;
                        }

                        $("#learn_id").val(learn_id);
                        $("#_html_tip").append(html);

                        $("#submit").css("display","inline");


                    }else{
                        updateAlert('生成题目失败，请重试!');
                        setTimeout(function(){
                            $('#top-alert').find('button').click();
                        },2000);
                    }
                }
            });

            
        }

        //导航高亮
        highlight_subnav('{:U('Student/index')}');
    </script>
</block>
